//
//  BalanceViewController.m
//  jingdongfang
//
//  Created by MTiMac02 on 2017/6/16.
//  Copyright © 2017年 ZhiYu Hao. All rights reserved.
//

#import "BalanceViewController.h"
#import "GetBalanceCashViewController.h"
#import "PhotoUpLoadAgreementViewController.h"
#import "UserUNidentyViewController.h"
@interface BalanceViewController (){
    UIButton *tixian;
    UIButton *btn;
}

@end

@implementation BalanceViewController
#pragma mark -生命周期
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor c2Color];
//    self.title = @"余额";
    self.title = NSLocalizedString(@"Balance", nil);
    [self loadUI];

}
-(void)loadUI
{
    UIImageView *imagView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 50 + 64,GSCALE(150) , GSCALE(150))];
    imagView.centerX=self.view.centerX;
    imagView.image = [UIImage imageNamed:@"图层-7"];
    [self.view addSubview:imagView];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, imagView.bottom + 15, self.view.width, 20)];
//    label.text = @"我的余额";
    label.text = NSLocalizedString(@"My Balance",nil);
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor grayColor];
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    UILabel *price = [[UILabel alloc] initWithFrame:CGRectMake(0, label.bottom + 15, self.view.width, 40)];
    price.text = [NSString stringWithFormat:@"¥ %@", self.money];
    [price setTextColor:[UIColor blackColor]];
    price.font = [UIFont systemFontOfSize:40];
    price.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:price];

    
    tixian = [UIButton buttonWithType:UIButtonTypeCustom];
    tixian.frame = CGRectMake(0, price.bottom + 40, GSCALE(300), GSCALE(44));
    tixian.centerX=self.view.centerX;
//    [tixian setTitle:@"提现" forState:UIControlStateNormal];
    [tixian setTitle:NSLocalizedString(@"Withdraw", nil) forState:UIControlStateNormal];
    tixian.titleLabel.font = [UIFont font18];
    tixian.layer.cornerRadius = 20.f;
    tixian.clipsToBounds = YES;
    [tixian setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tixian setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    tixian.userInteractionEnabled = self.money.floatValue >= 100 ? YES : NO;
    tixian.backgroundColor = self.money.floatValue >= 100 ? [UIColor appColor] : [UIColor grayColor];
    [tixian addTarget:self action:@selector(sureActionClick:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview: tixian];
    
    UILabel *declare = [[UILabel alloc]initWithFrame:CGRectMake(0, tixian.bottom + 15, self.view.width, 20)];
//    declare.text = @"提现金额不能低于100.00元,仅支持支付宝账户提现.";
    declare.text = NSLocalizedString(@"Withdrawal more than ￥100 RMB,please use Alipay.", nil);
    declare.textColor = [UIColor grayColor];
    declare.textAlignment = NSTextAlignmentCenter;
    [declare setFont:[UIFont systemFontOfSize:13]];
    [self.view addSubview:declare];
    
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, declare.bottom + 10, self.view.width, 30);
//    [btn setTitle:@" 不能提现? 立即身份认证 >" forState:UIControlStateNormal];
    [btn setTitle:NSLocalizedString(@"Withdrawal Unavailable. Verify Your ID  Now >", nil) forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn setTitleColor:[UIColor appColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(AuthenticationBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn.hidden = ([[IGUser getAuthens] integerValue] == 2)? YES : NO;
    [self.view addSubview:btn];
}

- (void)AuthenticationBtnClick:(UIButton *)sender
{
    if ([[IGUser getAuthens] integerValue] == 1)
    {
        //未认证
        PhotoUpLoadAgreementViewController *photoAgreenmentVC = [[UIStoryboard storyboardWithName:@"UserCertification" bundle:nil] instantiateViewControllerWithIdentifier:@"PhotoUpLoadAgreementViewController"];
        [self.navigationController pushViewController:photoAgreenmentVC animated:YES];
    }
    if ([[IGUser getAuthens] integerValue] == 3)
    {
        //待认证
//        [self presentMessageTips:@"身份待认证"];
        [self presentMessageTips:NSLocalizedString(@"ID to be Authenticated", nil)];
        return;
    }
    if([[IGUser getAuthens] integerValue]== 4)
    {
        //审核未通过
        UserUNidentyViewController *vc=[[UserUNidentyViewController alloc]initWithNibName:@"UserUNidentyViewController" bundle:nil];
        vc.content =[IGUser getAuthensContent];
        [UIViewController ig_pushViewController:vc animated:YES];
    }
}

- (void)sureActionClick:(UIButton *)button
{
    if (_money.doubleValue < 100.0)
    {
//        [self presentMessageTips:@"余额不足100, 无法提现"];
        [self presentMessageTips:NSLocalizedString(@"Balance below RMB 100, Withdrawal unavailable", nil)];
        return;
    }
    if ([[IGUser getAuthens] integerValue] == 1)
    {
        //未认证
//        [self presentMessageTips:@"身份未认证"];
        [self presentMessageTips:NSLocalizedString(@"ID Unauthenticated", nil)];
    }
    else if([[IGUser getAuthens] integerValue] == 2)
    {
        //通过
        GetBalanceCashViewController *vc=[[GetBalanceCashViewController alloc]initWithNibName:@"GetBalanceCashViewController" bundle:nil];
        vc.money =_money;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
    else
    {
        //是否认证（1未认证，2已认证，3待认证，3认证不通过）
        if ([[IGUser getAuthens] integerValue] == 3)
        {
            //待认证
//            [self presentMessageTips:@"身份待认证"];
            [self presentMessageTips:NSLocalizedString(@"ID to be Authenticated", nil)];
        }
        else if([[IGUser getAuthens] integerValue]== 4)
        {
            //未通过
//            [self presentMessageTips:@"未通过身份认证"];
            [self presentMessageTips:NSLocalizedString(@"ID Verification Failed", nil)];
        }
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
